package com.num2.service.lkw;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;

import com.num2.dao.lkw.IBalanceDao;
import com.num2.form.lkw.Balance_Money;
import com.num2.form.xjg.LoginForm;
import com.num2.model.lkw.BalanceModel;

@Service
public class BalanceService {
	@Resource
	private SqlSessionFactory sqlSessionFactory;
	private LoginForm loginform;
	public BalanceModel selectMoney(Balance_Money bm,HttpSession session) {
		//打开session
       SqlSession sqlSession = sqlSessionFactory.openSession();
        //通过 注解 获取 接口实现类的对象
       IBalanceDao balancedao = sqlSession.getMapper(IBalanceDao.class);
       
       //通过session得到的username获取user_id
       int userid = balancedao.selectName((String) session.getAttribute("user_name"));
       bm.setUser_id(userid);
       
       List<BalanceModel> it= balancedao.select(bm.getUser_id());
       sqlSession.close();
       return it.get(0);
	}

	public SqlSessionFactory getSqlSessionFactory() {
		return sqlSessionFactory;
	}

	public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionFactory = sqlSessionFactory;
	}

	public LoginForm getLoginform() {
		return loginform;
	}

	public void setLoginform(LoginForm loginform) {
		this.loginform = loginform;
	}
	
}
